function changeBasicInfoTab(){
	var mydisplay4=document.getElementById("personal_tab_nav1");
	var mydisplay5=document.getElementById("personal_tab_nav2");
	
	var myblock4=document.getElementsByClassName("person_content_info1").item(0);
	var myblock5=document.getElementsByClassName("person_content_info2").item(0);
	
	mydisplay4.onclick=function(){
		myblock4.style.display="block";
		myblock5.style.display="none";		
		mydisplay4.style.background="#ccc";
		mydisplay5.style.background="#fff";
		
	}
	mydisplay5.onclick=function(){
		myblock4.style.display="none";
		myblock5.style.display="block";		
		mydisplay5.style.background="#ccc";
		mydisplay4.style.background="#fff";
	
	}

	var mydisplay1=document.getElementById("order-left-info1");
	var mydisplay2=document.getElementById("order-left-info2");
	
	var myblock1=document.getElementsByClassName("order_right1").item(0);
	var myblock2=document.getElementsByClassName("order_right2").item(0);

	mydisplay1.onclick=function(){
		myblock2.style.display="none";
		myblock1.style.display="block";
		mydisplay1.style.background="#f4f4f4";
		mydisplay2.style.background="#fafafa";
		mydisplay1.style.color="#50b400";
		mydisplay2.style.color="#333";
	}
	mydisplay2.onclick=function(){
		myblock2.style.display="block";
		myblock1.style.display="none";
		mydisplay1.style.background="#fafafa";
		mydisplay2.style.background="#f4f4f4";
		mydisplay2.style.color="#50b400";
		mydisplay1.style.color="#333";
		$.post("loginServlet",{op:"indexDatas"},function(data){
			//alert(data.rows);
			var str="";
			var pageNo=0; //第几页
			var pageSize=0; //每页显示几条数据
			var indexs=1;

			$.each(data.rows,function(index,item){
				str+='<div id="tab1" class="jd_order_list"><ul><li class="jd_order_li"><span class="list_pic">';
				str+='<img id="orderPhoto" src="'+item.temp.split(",")[0]+'"></span><span class="list_title">';
				str+='<a id="orderJdName" class="list_title_names" href="javascript:show(\''+item.flag+'\')">'+item.flag+'</a></span><span class="list_money">';
				str+='<em class="yen">¥</em><em class="money_data" id="orderMoney">'+item.flags+'</em></span>';
				str+='<span class="list_date" id="orderDate">'+item.otime.split(" ")[0]+'</span><span class="list_state" id="orderState">'+item.statuss+'</span></li></ul></div>';
			});
			$("#order_list").html(str);
			
			$.post("loginServlet?t="+new Date(),{op:"OrderShowPage",index:indexs},function(data){
				
				$.each(data.rows,function(index,item){					
					pageNo=item.pageNo;  //获取当前的页数 
					pageSize=item.pageSize; //获取每页显示的条数
					totalPage=item.totalPage;//获取当前总页数
					totalSize=item.totalSize;//获取当前总条数
				});
				$("#pageNo").text(pageNo);
				$("#pageSize").text(pageSize);
				$("#totalPage").text(totalPage);
				$("#totalSize").text(totalSize);
			},"json");
		},"json");
		
		
	}
	
	
}

//订单的分页显示
function page(index){
	var pageNo=0; //第几页
	var pageSize=0; //每页显示几条数据
	var str="";
	$.post("loginServlet?t="+new Date(),{op:"OrderShowPage",index:index},function(data){
		
		$.each(data.rows,function(index,item){					
			pageNo=item.pageNo;  //获取当前的页数 
			pageSize=item.pageSize; //获取每页显示的条数
			totalPage=item.totalPage;//获取当前总页数
			totalSize=item.totalSize;//获取当前总条数
		});
		$.post("loginServlet?t="+new Date(),{op:"OrderShowPageInfo",pageNo:pageNo,pageSize:pageSize},function(datas){
			var str1="";
			//alert(data.rows);
			$.each(datas.rows,function(index,item){
				str1+='<div id="tab1" class="jd_order_list"><ul><li class="jd_order_li"><span class="list_pic">';
				str1+='<img id="orderPhoto" src="'+item.temp.split(",")[0]+'"></span><span class="list_title">';
				str1+='<a id="orderJdName" class="list_title_names" href="javascript:show(\''+item.flag+'\')">'+item.flag+'</a></span><span class="list_money">';
				str1+='<em class="yen">¥</em><em class="money_data" id="orderMoney">'+item.flags+'</em></span>';
				str1+='<span class="list_date" id="orderDate">'+item.otime.split(" ")[0]+'</span><span class="list_state" id="orderState">'+item.statuss+'</span></li></ul></div>';
			});
			$("#order_list").html(str1);
			$("#pageNo").text(pageNo);
			$("#pageSize").text(pageSize);
			$("#totalPage").text(totalPage);
			$("#totalSize").text(totalSize);
		},"json");
	},"json");
}

function show(temps){
	$.post("jdInfoServlet?t="+new Date(),{op:"JdParticular",jdName:temps},function(data){
		$.each(data.rows,function(index,item){
			window.location.href="jd_particular.html";
		});
	},"json");
}

//省市区三级级联
	
/*大多数浏览器都有读取和操作 XML 的内建 XML 解析器,微软IE基于ActiveX的MSXML
解析器把 XML 转换为 JavaScript 可访问的XML DOM对象	*/ 
function createIEXmlDom(){
	var arrs=["MSXML2.DOMDocument.6.0","MSXML2.DOMDocument.5.0","MSXML2.DOMDocument.4.0","MSXML2.DOMDocument.3.0","MSXML2.DOMDocument","Microsoft.XmlDom"];
	var ieXmlDom;
	for(var i=0;i<arrs.length;i++){
		try{
			ieXmlDom=new ActiveXObject(arrs[i]);
			return ieXmlDom;
		}catch(e){
			
		}
	}
	throw new Error("对不起,您的浏览器不支持...");
}

function xmlDom(){
	var dom;
	if(window.ActiveXObject){  //IE获取XML文档对象
		dom=createIEXmlDom();
	}else if(document.implementation&&document.implementation.createDocument){ //implementation：正在运行的程序
		//第一个参数是命名空间   第二个参数是跟标签   第三个一个doc类型
		dom=document.implementation.createDocument("","",null);
	}else{ //抛出异常
		throw new Error("对不起,您的浏览器不支持...");
	}
	return dom;
}

window.onload=function(){
	
	changeBasicInfoTab();
	//jddhShow(); //导航栏下拉信息
	//head_show();
	var dom;
	if(window.DOMParser&&!window.ActiveXObject){
		var xmlhttp=new XMLHttpRequest();
		xmlhttp.open("GET","city.xml",false);
		xmlhttp.send(null);
		if(xmlhttp.readyState==4){
			dom=xmlhttp.responseXML.documentElement;
		}
	}else{
		dom=xmlDom();
		dom.async=false;
		dom.load("city.xml");
	}
	
	//获取显示三级级联的三个下拉对象
	var pro=document.getElementById("province");
	var city=document.getElementById("city");
	var area=document.getElementById("area");
	
	//获取所有的省份
	var pros=dom.getElementsByTagName("province");
	
	for(var i=0;i<pros.length;i++){
		addOption(pros[i],pro);
	}
	
	//当省份发生改变时，后面的城市跟着改变,所以给省份的下拉对象添加一个onchange事件
	pro.onchange=function(){
		//获取当前选中的省份的编号
		var flag=pro.value;
		
		//清空以前的数据
		city.length=1;
		
		for(var i=0;i<pros.length;i++){
			//如果选中的省份的编号跟当前循环的对象编号一样
			if(pros[i].nodeType==1&&flag==pros[i].getAttribute("name")){
				//取出该省份下的所有市
				var cities=pros[i].childNodes;
				for(var j=0;j<cities.length;j++){
					if(cities[j].nodeType==1){
						addOption(cities[j],city);
					}
				}
				break;
			}
		}
	}
	
	//当城市发生变化的时候
	city.onchange=function(){
		var num=pro.value; //获取当前选中的省份
		var code=city.value; //获取当前选中的城市的编号
		area.length=1;//清空县下拉对象中原有的数据
		
		for(var i=0;i<pros.length;i++){
			//如果选中的省份的编号跟当前循环的对象编号一样
			if(pros[i].nodeType==1&&num==pros[i].getAttribute("name")){
				//获取当前省份下面的所有市
				var cities=pros[i].childNodes;
				
				
				//当前循环的城市跟选中的城市相同
				for(var j=0;j<cities.length;j++){
					if(cities[j].nodeType==1&&cities[j].getAttribute("name")==code){
						//获取当前城市下的所有地区
						var areas=cities[j].childNodes;
						
						for(var k=0;k<areas.length;k++){
							if(areas[k].nodeType==1){
								addOption(areas[k],area);
							}
						}
					}
				}
			}
		}
		
	}
	
}

//第一个是要添加的节点对象，第二个是要添加到的对象
function addOption(node,obj){
	if(node.nodeType==1){
		var opt=document.createElement("option");
		opt.appendChild( document.createTextNode( node.getAttribute("name") ) );
		opt.setAttribute("value",node.getAttribute("name"));
		obj.appendChild(opt);
		//<option value=''>湖南省</option>
	}
}


$(function(){	
	showUserInfo();
});



function preview(file){	
	var prevDiv = document.getElementById('headImage');
	var  img =document.getElementById("img");
	if (file.files && file.files[0]){		
		var reader = new FileReader();		
		reader.readAsDataURL(file.files[0]);
		reader.onload = function(evt){
			img.setAttribute("src",evt.target.result);
		}  
	}
	
}

function savePwd(){
	var oldpwd=$.trim($("#oldpwd").val());
	var newpwd=$.trim($("#newpwd").val());
	var checkpwd=$.trim($("#checkpwd").val());
	//alert(oldpwd +"" +newpwd+""+checkpwd);
	if(newpwd==checkpwd){
		$.post("loginServlet",{op:'updataPwd',oldpwd:oldpwd,newpwd:newpwd},function(data){
			data=parseInt($.trim(data));
			if(data==1){
				alert("密码修改成功...");
				getUserLoginInfo();
			}else{
				alert("您输入的旧密码错误，请重新输入");	
			}
		})
	}else{
		$("#checkbox2").text("新置密码两次输入不一致，请重新输入").css("display","inline-block");
	}
}



function saveInfo(){
	
	var name=$.trim($("#name").val());
	
	var truename=$.trim($("#truename").val());
	var identify=$.trim($("#identify").val());
	var tel=$.trim($("#tel").val());
	var sex;
	if(document.getElementById("userSexM").checked){
		sex=0;//男
	}else if(document.getElementById("userSexF").checked){
		sex=1;//女
	}
	var province=$.trim($("#province").val());
	var city=$.trim($("#city").val());
	var area=$.trim($("#area").val());
	var QQ=$.trim($("#QQ").val());
	//alert(name+" "+truename+" "+identify+""+tel+""+province+""+city+""+area+""+QQ);


	$.ajaxFileUpload({		
		url:"loginServlet?op=updateUserInfo",
		secureuri:false,
		fileElementId:"upfile",
		
		dataType:"json",
		data:{"name":name,"truename":truename,"identify":identify,"tel":tel,"province":province,"city":city,"area":area,"sex":sex,"QQ":QQ},
		success:function(data,status){
			data=parseInt($.trim(data));
			if(data==1){
				alert("保存成功...");
				getUserLoginInfo();
			}else{
				alert("保存失败...");	
			}
		}
	});
	
}

function showUserInfo(){	
	var upfile=$("#upfile");
	var name=$("#name");
	var truename=$("#truename");
	var identify=$("#identify");
	var tel=$("#tel");
	//var userSexM=$("#userSexM");
	//var userSexF=$("#userSexF");
	var province=$("#province");
	var city=$("#city");
	var area=$("#area");
	var QQ=$("#QQ");
	
	$.post("loginServlet?t="+new Date(),{op:'showUserInfo'},function(data){	
	var str="";
	if(isNaN(data)){
		if(data.showUserInfo.sex==0){
			
			str+='<ul class="basicinfo"><li><label id="photo_label" class="label">';
			str+='<span class="small_pic"></span>当前头像</label><div id="headImage" class="headImage"><img id="img" name="img"  src="'+data.showUserInfo.photos.split("'")[1]+'"/></div>';
			str+='<input type="file"  size="10" multiple id="upfile" name="upfile" onchange="preview(this)" /></li>';
			str+='<li><label class="label"><span class="small_pic"></span>昵　　称</label><input id="name" type="text"  maxlength="16"  name="txtsmallName" value="'+data.showUserInfo.uname+'" class="new_error">';
			str+='<label id="txtsmallNamelb" class="right_message" style="display: inline;"><b class="tip_info" id="tip_name" style="display:none">请输入昵称</b></label></li>';
			str+='<li><label class="label"><span class="small_pic"></span>真实姓名 </label><input id="truename" type="text"  maxlength="16" name="txtName" value="'+data.showUserInfo.tname+'" class="new_error">';
			str+='<label id="txtNamelb" class="right_message" style="display: inline;"><b class="tip_info" style="display:none">请输入真实姓名称</b></label></li>';
			str+='<li><label class="label"><span class="small_pic"></span>证件号码</label><input id="identify" type="text"  maxlength="18" name="txtID" value="'+data.showUserInfo.idcard+'" class="new_error">';
			str+='<label id="txtsmallNamelb" class="right_message" style="display: inline;"><b class="tip_info" style="display:none">请输入有效证件号码</b></label></li>';
			str+='<li><label class="label"><span class="small_space"></span>手机号码</label><input id="tel" type="text" maxlength="18" name="tel" value="'+data.showUserInfo.tel+'" class="new_error">';
			str+='<label id="telID" class="right_message" style="display: inline;"><b class="tip_info" style="display:none">请输入手机号码</b></label></li>';
			str+='<li><label class="label"><span class="small_space"></span>性　　别 </label><input id="userSexM" type="radio" name="sex" checked=true> 男&nbsp;&nbsp;&nbsp;<input id="userSexF" type="radio"  name="sex"> 女</li>';
			str+='<li><label class="label"><span class="small_space"></span>所在城市</label><select id="province"><option> '+data.showUserInfo.province+'</option></select> 省';
			str+='<select id="city"><option >'+data.showUserInfo.city+'</option></select> 市';
			str+='<select id="area"><option >'+data.showUserInfo.area+'</option></select> 区</li>';
			str+='<li><label class="label"><span class="small_space"></span>QQ</label><input id="QQ" class="c_qq" type="text" value="'+data.showUserInfo.QQ+'" name="txtQQ"></li>';
			str+='<li id="tipcontent"><p>同程旅游郑重承诺：</p><p>我们将尊重您的个人隐私，您的个人信息不会被公开。</p><p>我们会为您量身定制个性化的服务，让您享受更优质的出行体验。</p></li>';
			str+='<li class="basic_submit"><span id="subbutton" name="mySub" onclick="javascript:saveInfo()">保 存</span></li></ul>';
		
			
		}else{
		
			str+='<ul class="basicinfo"><li><label id="photo_label" class="label">';
			str+='<span class="small_pic"></span>当前头像</label><div id="headImage" class="headImage" ><img id="img" name="img" src="'+data.showUserInfo.photo+'"/></div>';
			str+='<input type="file"  size="10" multiple id="upfile"  name="upfile" onchange="preview(this)"/></li>';
			str+='<li><label class="label"><span class="small_pic"></span>昵　　称</label><input id="name" type="text"  maxlength="16"  name="txtsmallName" value="'+data.showUserInfo.uname+'" class="new_error">';
			str+='<label id="txtsmallNamelb" class="right_message" style="display: inline;"><b class="tip_info" id="tip_name" style="display:none">请输入昵称</b></label></li>';
			str+='<li><label class="label"><span class="small_pic"></span>真实姓名 </label><input id="truename" type="text"  maxlength="16" name="txtName" value="'+data.showUserInfo.tname+'" class="new_error">';
			str+='<label id="txtNamelb" class="right_message" style="display: inline;"><b class="tip_info" style="display:none">请输入真实姓名称</b></label></li>';
			str+='<li><label class="label"><span class="small_pic"></span>证件号码</label><input id="identify" type="text"  maxlength="18" name="txtID" value="'+data.showUserInfo.idcard+'" class="new_error">';
			str+='<label id="txtsmallNamelb" class="right_message" style="display: inline;"><b class="tip_info" style="display:none">请输入有效证件号码</b></label></li>';
			str+='<li><label class="label"><span class="small_space"></span>手机号码</label><input id="tel" type="text" maxlength="18" name="tel" value="'+data.showUserInfo.tel+'" class="new_error">';
			str+='<label id="telID" class="right_message" style="display: inline;"><b class="tip_info" style="display:none">请输入手机号码</b></label></li>';
			str+='<li><label class="label"><span class="small_space"></span>性　　别 </label><input id="userSexM" type="radio" name="sex"> 男&nbsp;&nbsp;&nbsp;<input id="userSexF" type="radio" checked=true name="sex"> 女</li>';
			str+='<li><label class="label"><span class="small_space"></span>所在城市</label><select id="province"><option> '+data.showUserInfo.province+'</option></select> 省';
			str+='<select id="city"><option >'+data.showUserInfo.city+'</option></select> 市';
			str+='<select id="area"><option >'+data.showUserInfo.area+'</option></select> 区</li>';
			str+='<li><label class="label"><span class="small_space"></span>QQ</label><input id="QQ" class="c_qq" type="text" value="'+data.showUserInfo.QQ+'" name="txtQQ"></li>';
			str+='<li id="tipcontent"><p>同程旅游郑重承诺：</p><p>我们将尊重您的个人隐私，您的个人信息不会被公开。</p><p>我们会为您量身定制个性化的服务，让您享受更优质的出行体验。</p></li>';
			str+='<li class="basic_submit"><span id="subbutton" name="mySub" onclick="javascript:saveInfo()">保 存</span></li></ul>';
			
		}
					
	}else{
		location.href="login.html";
	}
	$("#person_content_info1").html(str);
	},"json");
}



